﻿<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>生产计划</title>
    <meta name="renderer" content=padding>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/js/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    @* <script src="~/js/layui/layui.js"></script> *@
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/Scripts/formSelect/multiSelect.js"></script>
    <script type="text/html" id="barDemo">
        @* <a title="查看" href="javascript:;"  lay-event="view" id="frmView"><i class="layui-icon">&#xe615;</i></a> *@
        <a title="生产打码" href="javascript:;"  lay-event="print" id="frmPrint"><i class="layui-icon">&#xe66d;</i></a>
        <a title="计划用料" href="javascript:;" lay-event="edit" id="frmEdit"><i class="layui-icon">&#xe62a;</i></a>
        <a title="废料录入" href="javascript:;" lay-event="fllr" id="frmFllr"><i class="layui-icon">&#xe656;</i></a>
        <a title="工艺打印" href="javascript:;" lay-event="gydy" id="frmGydy"><i class="layui-icon">&#xe655;</i></a>
        <a title="计划完成" href="javascript:;" lay-event="complete" id="frmFinish"><i class="layui-icon">&#x1005;</i></a>
    </script>
</head>
<body>
    <div class="layui-fluid" style="width:100%;">
        <div id="bDiv">
        </div>
        <div style="float:left;width:100%;">
            <div class="layui-card">

                <div class="layui-card-body" style="margin-top:5px">
                    <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="plCode" placeholder="计划编码" autocomplete="off" class="layui-input" id="plCode">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="spec" placeholder="规 格" autocomplete="off" class="layui-input" id="spec">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select id="gxStatus" name="gxStatus">
                                <option value="">完成状态</option>
                                <option value="1">完成</option>
                                <option value="0">未完成</option>
                            </select>
                        </div>
                    </form>
                </div>


                <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                    <table class="layui-hide" id="list" lay-filter="list"></table>
                </div>
            </div>


        </div>
    </div>
</body>
</html>
<script src="~/js/framework/sysframework.js"></script>
<script src="~/js/framework/commonjs.js"></script>
<script src="~/js/sysweb/planjs.js"></script>
<script>
    var webCode = "";

    var selectList = new Array();

    $(function () {
        webCode = getUrlVariable("menuCode");
        BannerData(webCode, "bDiv");
        DictionaryDropDown("pst", "status", "ps-doing", false);
        loadData();
    })
    function openQueryWin() {
        gjQuery = true;
        InfoOpenPage("../System/QueryWeb?webCode=" + webCode, "高级检索", "85%", "80%");
    }
    function openWin() {
        InfoOpenPage("../Plan/UpdatePlanNew?dataId=0", "创建计划", "85%", "80%", true);
    }



    var dUrl = "../Bar/getDataList?dataType=proBarPrint&condition=";
    /**
     * 加载数据
     * **/
    function loadData() {
        if (!gjQuery) {
            qStr = FormToJson("qForm");
        }

        gjQuery = false;
        layui.use('table', function () {
            var conditon = JSON.stringify(qStr);
            var table = layui.table;

            table.render({
                elem: '#list'
                , height: 'full-200'   //固定高度-即固定表头固定第一行首行
                , cols: [[ //标题栏
                    // { type: 'checkbox' },
                      { field: 'plCode', align: 'center', title: '计划编码', width: 120, sort: true }
                    , { field: 'proName', align: 'center', title: '生产存货', width: 170 }
                    , { field: 'spec', align: 'center', title: '规格', width: 150 }
                    , { field: 'number', align: 'center', title: '成品数量', width: 100 }
                    , { field: 'cuName', align: 'center', title: '关联客户', width: 200 }
                    , { field: 'jfDate', align: 'center', title: '完工日期', width: 120 }
                    , { field: 'planTypeName', align: 'center', title: '计划类型', width: 120 }
                    , { field: 'gxName', align: 'center', title: '生产工序', width: 120 }
                    , { field: 'gxNumber', align: 'center', title: '工序生产数', width: 130 }
                    , { field: 'right', align: 'center', title: '数据操作', toolbar: '#barDemo', width: 130, fixed: 'right' }
                ]], done: function (res, curr, count) {
                    // $("[data-field='id']").css('display', 'none');//隐藏列
                    currPage = curr;
                    TablePowerHide();
                    $.each(res['data'], function (i, j) {
                        if (j['isFinish'] == "1") {
                            TableRowColor('layui-table-main', i, '#C3FDB8');
                        }
                    });
                }
                , url: dUrl + conditon
                , skin: 'row' //表格风格
                , even: true
                , page: true //是否显示分页
                , limits: [20, 25, 30]
                , limit: 20 //每页默认显示的数量
                , id: "list"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == "view") {

                } else if (obj.event == "print") {// 打印
                    if (data.isFinish == "1") {
                        layer.msg("工序已完成，禁止再进行生产打码", { icon: 2 });
                        return;
                    }
                    if (data.status != "ps-doing") {
                        layer.msg("非生产状态，禁止生产打码", {icon:2});
                        return;
                    }
                    var printUrl = "printBarTools://";
                    const full = location.protocol + '//' + location.host;
                    $.ajax({
                        url: "../Base/GetLoginUser",
                        dataType: "json",
                        type: "POST",
                        async: false,
                        success: function (rsl) {
                            if (rsl.result) {
                                var userStr = rsl.data;
                                var user = JSON.parse(userStr);
                                var query = {
                                    type: "proBarPrint",
                                    userCode: user.userCode,
                                    baseCode: user.baseCode,
                                    plCode: data.plCode,
                                    gxCode: data.gxCode,
                                    gxName: data.gxName,
                                    jfDate: data.jfDate,
                                    planNum: data.number,
                                    number: data.number,
                                    proCode: data.proCode,
                                    proName: data.proName,
                                    spec: data.spec,
                                    proMeter: data.proMeter,
                                    gxNumber: data.gxNumber,
                                    zhxBz: data.zhxBz,
                                    cu_customer: data.cuName,
                                    unitName: data.unitName,
                                    cu_bcp: data.cu_bcp,
                                    produce_spec: data.produce_spec,
                                    produce_proName: data.produce_proName,
                                    produce_unitName: data.produce_unitName

                                };
                                //console.log(printUrl + JSON.stringify(query))
                                window.location.href = printUrl + JSON.stringify(query);

                            } else {
                                layer.msg(info.message);
                            }
                        }
                    });
                } else if (obj.event == "complete") { // 完成
                    if (data.isFinish == "1") {
                        layer.msg("计划工序已完成，无法重复完成");
                        return;
                    }
                    layer.confirm('确定要完成当前计划？', function (index) {
                        finishPlanGx(data.plCode, data.gxCode)
                        layer.close(index);

                    });

                } else if (obj.event == "edit") {//计划用料
                    InfoOpenPage("../Plan/pMUseEdit?plCode=" + data.plCode+"&gxCode="+data.gxCode, "编辑计划用料", "85%", "80%", true);
                } else if (obj.event == "fllr") {//废料录入
                    InfoOpenPage("../Plan/WasteEdit?plCode=" + data.plCode + "&gxCode=" + data.gxCode + "&gxName=" + data.gxName +
                        "&isFinish=" + data.isFinish + "&MaxFlNum=" + data.MaxFlNum, "废料录入", "95%", "90%");
                }
                else if (obj.event == "gydy") {//工艺打印
                    window.location.href = "../Plan/gyPrint?plCode=" + data.plCode + "&gxCode=" + data.gxCode;
                }
            });

        });

    }

    var qStr = "";
    /**
     * 获取高级查询字符串
     * **/
    function GetQueryPar(queryStr) {
        qStr = queryStr;
        loadData();
    }

    /**
     * 标记计划工序为完成
     * **/
    function finishPlanGx(plCode, gxCode) {
        $.ajax({
            url: "../Plan/finishPlanGx",
            data: { plCode: plCode, gxCode: gxCode },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.result) {
                    loadData();
                } else {
                    layer.msg(data.message);
                }
            }
        });
    }


</script>
